<template>
  <el-row :gutter="20">
    <el-col :sm="2" class="hidden-xs-only" style="opacity:0;">左侧占位</el-col>
    <el-col :xs="24" :sm="20">
      <el-card style="background-color: rgba(255,255,255,0.9)" class="friends-card">
        <div slot="header" class="total">
          <div class="titleIndex">
            <i class="el-icon-link"></i>
            <span>友情链接</span>
          </div>
        </div>
        <div class="friends-container">
          <div class="friends-intro">
            <p>欢迎交换友情链接！如果您有意向，请联系我。</p>
          </div>
          <el-divider></el-divider>
          <div class="friends-list">
            <el-row :gutter="20">
              <el-col :xs="24" :sm="12" :md="8" :lg="6" v-for="friend in friendList" :key="friend.id" class="friend-item">
                <el-card shadow="hover" class="friend-card">
                  <div class="friend-avatar">
                    <el-avatar :size="60" :src="friend.avatar">
                      <i class="el-icon-user-solid" style="font-size: 30px;"></i>
                    </el-avatar>
                  </div>
                  <div class="friend-info">
                    <h4 class="friend-name">
                      <a :href="friend.url" target="_blank" rel="noopener noreferrer">{{ friend.name }}</a>
                    </h4>
                    <p class="friend-desc">{{ friend.description }}</p>
                    <div class="friend-meta">
                      <el-tag size="mini" type="info">{{ friend.category }}</el-tag>
                    </div>
                  </div>
                </el-card>
              </el-col>
            </el-row>
          </div>
          <el-divider></el-divider>
          <div class="apply-section">
            <h3>申请友链</h3>
            <el-form :model="applyForm" :rules="applyRules" ref="applyFormRef" label-width="100px">
              <el-form-item label="网站名称" prop="name">
                <el-input v-model="applyForm.name" placeholder="请输入网站名称"></el-input>
              </el-form-item>
              <el-form-item label="网站链接" prop="url">
                <el-input v-model="applyForm.url" placeholder="请输入网站链接，如：https://example.com"></el-input>
              </el-form-item>
              <el-form-item label="网站描述" prop="description">
                <el-input 
                  v-model="applyForm.description" 
                  type="textarea" 
                  :rows="3"
                  placeholder="请输入网站描述"
                ></el-input>
              </el-form-item>
              <el-form-item label="联系方式" prop="contact">
                <el-input v-model="applyForm.contact" placeholder="请输入邮箱或QQ等联系方式"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitApply">提交申请</el-button>
                <el-button @click="resetForm">重置</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </el-card>
    </el-col>
    <el-col :sm="2" class="hidden-xs-only" style="opacity:0;">右侧占位</el-col>
  </el-row>
</template>

<script>
export default {
  name: 'Friends',
  data() {
    return {
      friendList: [
        {
          id: 1,
          name: '技术博客A',
          url: 'https://example.com',
          description: '专注于前端技术分享',
          avatar: 'https://via.placeholder.com/60',
          category: '技术博客'
        },
        {
          id: 2,
          name: '学习笔记B',
          url: 'https://example.com',
          description: '记录学习过程的点滴',
          avatar: 'https://via.placeholder.com/60',
          category: '个人博客'
        },
        {
          id: 3,
          name: '开发者社区C',
          url: 'https://example.com',
          description: '开发者技术交流社区',
          avatar: 'https://via.placeholder.com/60',
          category: '技术社区'
        },
        {
          id: 4,
          name: '编程教程D',
          url: 'https://example.com',
          description: '提供优质的编程教程',
          avatar: 'https://via.placeholder.com/60',
          category: '教程网站'
        },
        {
          id: 5,
          name: '开源项目E',
          url: 'https://example.com',
          description: '分享开源项目和实践经验',
          avatar: 'https://via.placeholder.com/60',
          category: '开源项目'
        },
        {
          id: 6,
          name: '技术论坛F',
          url: 'https://example.com',
          description: '技术讨论和经验分享',
          avatar: 'https://via.placeholder.com/60',
          category: '技术论坛'
        }
      ],
      applyForm: {
        name: '',
        url: '',
        description: '',
        contact: ''
      },
      applyRules: {
        name: [
          { required: true, message: '请输入网站名称', trigger: 'blur' }
        ],
        url: [
          { required: true, message: '请输入网站链接', trigger: 'blur' },
          { type: 'url', message: '请输入正确的网址', trigger: 'blur' }
        ],
        description: [
          { required: true, message: '请输入网站描述', trigger: 'blur' }
        ],
        contact: [
          { required: true, message: '请输入联系方式', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitApply() {
      this.$refs.applyFormRef.validate((valid) => {
        if (valid) {
          // 这里可以调用API提交申请
          this.$message.success('友链申请已提交，我们会尽快审核！')
          this.resetForm()
        } else {
          this.$message.error('请填写完整信息')
        }
      })
    },
    resetForm() {
      this.$refs.applyFormRef.resetFields()
    }
  }
}
</script>

<style scoped>
.friends-card {
  margin-top: 20px;
}

.titleIndex {
  display: flex;
  align-items: center;
  font-size: larger;
  font-weight: bold;
}

.titleIndex i {
  margin-right: 10px;
  color: #409eff;
  font-size: 20px;
}

.friends-container {
  padding: 20px 0;
}

.friends-intro {
  text-align: center;
  padding: 20px;
  background-color: #f5f7fa;
  border-radius: 4px;
  margin-bottom: 20px;
}

.friends-intro p {
  color: #606266;
  font-size: 14px;
  margin: 0;
}

.friends-list {
  margin: 30px 0;
}

.friend-item {
  margin-bottom: 20px;
}

.friend-card {
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  height: 100%;
}

.friend-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.friend-avatar {
  margin-bottom: 15px;
}

.friend-info {
  padding: 10px 0;
}

.friend-name {
  margin: 10px 0;
  font-size: 16px;
}

.friend-name a {
  color: #303133;
  text-decoration: none;
  transition: color 0.3s;
}

.friend-name a:hover {
  color: #409eff;
}

.friend-desc {
  color: #909399;
  font-size: 13px;
  margin: 10px 0;
  min-height: 40px;
  line-height: 1.6;
}

.friend-meta {
  margin-top: 10px;
}

.apply-section {
  margin-top: 30px;
  padding: 20px;
  background-color: #f9fafc;
  border-radius: 4px;
}

.apply-section h3 {
  margin-bottom: 20px;
  color: #303133;
}

@media screen and (max-width: 768px) {
  .friends-container {
    padding: 10px 0;
  }
  
  .friend-item {
    margin-bottom: 15px;
  }
  
  .apply-section {
    padding: 15px;
  }
}
</style>

